package com.hzg.service.impl;

import com.hzg.service.INoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @ Description: TODO
 * @ Author: 卓哥
 * @ Date: 2020/8/5 18:47
 * @ Version: 1.0
 */
@Service
public class NoticeServiceImpl implements INoticeService {
    @Autowired
    private StringRedisTemplate template;
    @Override
    public int viewNum(String id) {
        //key设计考虑问题:1.唯一性 2.可读性  3.灵活性 4.时效性
        String key="notice:"+id;//增加可读性
        //如果key不存在,默认是从0开始的
        //increment等价于 incr id(key) --->+1
        Long increment = template.opsForValue().increment(key);
        return increment.intValue();
    }
}
